<template>
  <MyVanskeleton :row="3" :loading="loading">
    <template v-slot:my-content>
      <div class="company-style">
        <!-- 导航栏 start -->
        <van-nav-bar
          title="简历"
          z-index="9999"
          @click-left="onBack"
          left-arrow
          fixed
        >
          <template #right>
            <van-icon
              :name="isCollect === true ? 'star' : 'star-o'"
              size="20"
              @click="onCollectClick"
            />
          </template>
        </van-nav-bar>
        <!-- 导航栏 end -->

        <!-- 内容 start -->
        <div class="content-top resume-perview">
          <!-- 基本信息 -->
          <div class="module">
            <div class="basic">
              <p class="name">
                <b>{{ resumeInfo.basicInfo_name }}</b>
                <span>更新时间：{{ resumeInfo.basicInfo_updateTimeStr }}</span>
                <img
                  :src="resumeInfo.basicInfo_logo"
                  @click="viewLogo(resumeInfo.basicInfo_logo)"
                  alt=""
                  v-if="resumeInfo.basicInfo_logo != ''"
                />
                <template v-else>
                  <img
                    src="@/assets/img/my/no-avatar-boy.png"
                    alt=""
                    v-if="resumeInfo.basicInfo_sex === '男'"
                  />
                  <img src="@/assets/img/my/no-avatar-girl.png" alt="" v-else />
                </template>
              </p>
              <p class="info01">
                <span>{{ resumeInfo.basicInfo_sex }}</span>
                <span>{{ resumeInfo.basicInfo_age }}岁</span>
                <span>{{ resumeInfo.basicInfo_edu }}</span>
                <span>{{ resumeInfo.basicInfo_workyears }}</span>
              </p>
              <p class="info02" v-if="resumeInfo.basicInfo_mz != ''">
                <span class="mz">{{ resumeInfo.basicInfo_mz }}</span>
                <span class="zzmm">{{ resumeInfo.basicInfo_zzmm }}</span>
                <span class="hy">{{ resumeInfo.basicInfo_marry }}</span>
                <span class="hj">{{ resumeInfo.basicInfo_hk }}</span>
                <span class="jzd">{{ resumeInfo.basicInfo_area }}</span>
                <span class="byyx">{{ resumeInfo.basicInfo_school }}</span>
                <span class="sxzy">{{ resumeInfo.basicInfo_zy }}</span>
                <span class="bysj">{{ resumeInfo.basicInfo_byDateStr }}</span>
              </p>
            </div>
            <!-- 备注 -->
            <div class="remark" @click="onRemark">
              <label><van-icon name="label" />备注</label>
              <!-- 备注前 -->
              <p class="no" v-if="remark === ''">
                <span>请添加对此人的备注</span>
              </p>
              <p class="yes" v-else>
                <span>{{ remark }}</span>
                <sub>修改</sub>
              </p>
            </div>
          </div>

          <!-- 简历反馈 -->
          <div class="module" style="padding: 12px 16px" v-if="rowid != 0">
            <div class="feedback">
              <!-- 未填写 -->
              <div class="no" v-if="applyResult === ''" @click="onResult">
                <p>
                  <b>该简历是否符合您的招聘要求</b>
                  <span>即时处理简历将提高您的职位排名</span>
                  <span>处理结果将反馈给求职者</span>
                </p>
                <van-button plain color="#f70" text="立即处理"></van-button>
              </div>

              <!-- 已填写 -->
              <div class="yes" v-else>
                <p>
                  <b>该简历是否符合您的招聘要求</b>
                  <span>{{ applyResult }}</span>
                </p>
              </div>
            </div>
          </div>

          <!-- 求职意向 -->
          <div class="module" v-if="resumeInfo.hasJobWanted === true">
            <p class="tab">求职意向</p>
            <div class="box hope">
              <p>
                <label>性质</label>
                <span>{{ resumeInfo.jobWanted_jobtype }}</span>
              </p>
              <p>
                <label>薪资</label>
                <span>{{ resumeInfo.jobWanted_monthpay }}</span>
              </p>
              <p>
                <label>行业</label>
                <span>{{ resumeInfo.jobWanted_companyHY }}</span>
              </p>
              <p>
                <label>职位</label>
                <span>{{ resumeInfo.jobWanted_job }}</span>
              </p>
              <p>
                <label>地区</label>
                <span>{{ resumeInfo.jobWanted_area }}</span>
              </p>
            </div>
          </div>

          <template v-if="isPublic === true">
            <!-- 联系方式 -->
            <div class="module">
              <p class="tab">联系方式</p>
              <div class="box contact">
                <p v-if="resumeInfo.basicInfo_tel != ''">
                  <b>{{ resumeInfo.basicInfo_tel }}</b>
                  <span @click="toCall(resumeInfo.basicInfo_tel)"
                    >拨打电话</span
                  >
                </p>
                <p @click="onGetLink" v-else>
                  <b>未获取</b>
                  <span>获取号码</span>
                </p>
              </div>
            </div>

            <!-- 教育培训 -->
            <div class="module" v-if="resumeInfo.hasEdu === true">
              <p class="tab">教育培训</p>
              <ul class="box list02">
                <li v-for="(item, index) in resumeInfo.list_edu" :key="index">
                  <b>{{ item.school }}</b>
                  <span>{{ item.edu }} | {{ item.zy }}</span>
                  <span v-if="item.dateStr != ''">{{ item.dateStr }}</span>
                  <span
                    class="profile"
                    v-if="item.content != ''"
                    v-html="item.content"
                  ></span>
                </li>
              </ul>
            </div>

            <!-- 工作经历 -->
            <div class="module" v-if="resumeInfo.hasWork === true">
              <p class="tab">工作经历</p>
              <ul class="box list02">
                <li v-for="(item, index) in resumeInfo.list_work" :key="index">
                  <b>{{ item.companyName }}</b>
                  <span>{{ item.xz }} | {{ item.hy }}</span>
                  <span>{{ item.dateStr }}</span>
                  <b>{{ item.job }}</b>
                  <span
                    class="profile"
                    v-if="item.content != ''"
                    v-html="item.content"
                  ></span>
                </li>
              </ul>
            </div>

            <!-- 自我评价 -->
            <div class="module" v-if="resumeInfo.self != ''">
              <p class="tab">自我评价</p>
              <div class="box myself">
                <span v-html="resumeInfo.self"></span>
                <!-- <sub>查看全部</sub> -->
              </div>
            </div>

            <!-- 专业技能 -->
            <div class="module" v-if="resumeInfo.hasSkill === true">
              <p class="tab">专业技能</p>
              <ul class="box list01">
                <li v-for="(item, index) in resumeInfo.list_skill" :key="index">
                  <span>{{ item.Skill_Name }}</span>
                  <i></i>
                  <span>{{ item.Skill_level }}</span>
                </li>
              </ul>
            </div>

            <!-- 获得证书 -->
            <div class="module" v-if="resumeInfo.hasZS === true">
              <p class="tab">获得证书</p>
              <ul class="box list01">
                <li v-for="(item, index) in resumeInfo.list_ZS" :key="index">
                  <span>{{ item.License_NameValue }}</span>
                  <i></i>
                  <span>{{ item.Date_Time }}</span>
                </li>
              </ul>
            </div>

            <!-- 附加信息 -->
            <div class="module" v-if="resumeInfo.hasAddInfo === true">
              <p class="tab">附加信息</p>
              <ul class="box list03">
                <li
                  v-for="(item, index) in resumeInfo.list_AddInfo"
                  :key="index"
                >
                  <b>{{ item.T_Name }}</b>
                  <span v-html="item.Information"></span>
                </li>
              </ul>
            </div>
          </template>
          <!-- 保密简历 -->
          <div class="privary-hint" v-else>
            <span>保密简历只显示部分信息，您可在线和Ta沟通</span>
          </div>
        </div>
        <!-- 内容 end -->

        <!-- 底部按钮 start -->
        <div class="resume-perview-btn">
          <van-button
            type="primary"
            color="#f70"
            text="通知面试"
            @click="onInterview"
            v-if="resumeInfo.basicInfo_tel != ''"
          ></van-button>
          <van-button
            type="primary"
            color="#07f"
            text="在线沟通"
            @click="toIM"
          ></van-button>
        </div>

        <!-- 底部按钮 end -->

        <van-popup v-model="showRemark" class="resume-perview-popu"
          ><ResumeRemark :resumeid="resumeid" />
        </van-popup>
        <van-popup v-model="showResult" class="resume-perview-popu"
          ><ResumeResult :resumeid="resumeid" :rowid="rowid"
        /></van-popup>
      </div>
    </template>
  </MyVanskeleton>
</template>

<script>
import { NavBar, Icon, Toast, Button, Dialog, Popup, ImagePreview } from "vant";
import MyVanskeleton from "@/components/MyVanskeleton.vue";
import {
  CompanyResumeShowRsumeInfo,
  CompanyResumeIsCollectResume,
  CompanyResumeCollectResume,
  CompanyResumeGetLinks,
} from "@/util/http";
import ResumeRemark from "@/pages/company/resume/resumeInfo/components/ResumeRemark.vue";
import ResumeResult from "@/pages/company/resume/resumeInfo/components/ResumeResult.vue";
import Global from "@/Global";
import { mixin_call } from "@/mixin/mixins";
export default {
  name: "ResumeInfo",
  components: {
    MyVanskeleton,
    [NavBar.name]: NavBar,
    [Icon.name]: Icon,
    [Button.name]: Button,
    [Popup.name]: Popup,
    ResumeRemark,
    ResumeResult,
  },
  props: ["title", "resumeid", "rowid", "isFromIM"],
  mixins: [mixin_call],
  mounted() {
    this.onLoad();
    this.$bus.$on(Global.bus_company_resume_showinfo_update, (res) => {
      this.showRemark = false;
      this.showResult = false;
      if (res === 1) {
        this.onLoad();
      }
    });
    CompanyResumeIsCollectResume(this.resumeid).then((res) => {
      // console.log(res);
      this.isCollect = res;
    });
  },
  // 定义属性
  data() {
    return {
      loading: true,
      resumeInfo: {},
      remark: "",
      applyResult: "",
      isPublic: false,
      isCollect: false, //是否收藏
      showRemark: false,
      showResult: false,
    };
  },
  // 方法集合
  methods: {
    onLoad() {
      CompanyResumeShowRsumeInfo(this.resumeid, this.rowid).then((res) => {
        // console.log(res);
        this.loading = false;
        if (res.result === 1) {
          this.resumeInfo = res.data;
          this.isPublic = res.isPublic;
          this.remark = res.remark;
          this.applyResult = res.applyResult;
        } else {
          Dialog.confirm({
            message: res.msg,
            confirmButtonText: "退出",
          })
            .then(() => {
              this.$router.go(-1);
            })
            .catch(() => {
              // on cancel
              this.$router.go(-1);
            });
        }
      });
    },
    onCollectClick() {
      CompanyResumeCollectResume(this.resumeid, !this.isCollect).then((res) => {
        Toast(res.msg);
        if (res.result === 1) {
          this.isCollect = !this.isCollect;
        }
      });
    },
    onRemark() {
      // console.log("onRemark");
      this.showRemark = true;
    },
    onResult() {
      this.showResult = true;
    },
    onInterview() {
      this.$router.push({
        name: "company-resume-interview",
        query: { resumeid: this.resumeid },
        params: { phone: this.resumeInfo.basicInfo_tel, rowid: this.rowid },
      });
    },
    onGetLink() {
      Dialog.confirm({
        message: "获取联系方式，将扣除一个简历数",
        confirmButtonText: "获取",
      })
        .then(() => {
          CompanyResumeGetLinks(this.resumeid).then((res) => {
            Toast(res.msg);
            if (res.result === 1) {
              this.onLoad();
            }
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    toIM() {
      if (this.isFromIM) {
        this.$router.go(-1);
      } else {
        let personid = this.resumeid.substring(0, 7);
        this.$router.push({
          name: "company-im",
          query: { cid: 0, personid },
        });
      }
    },
    viewLogo(url) {
      ImagePreview([url]);
    },
  },
};
</script>

<style lang="less">
@import "vant/lib/index.less";
@import "@/assets/css/company.less";
</style>
